package com.chencong.transform;

import com.chencong.env.FlinkTableEnv;
import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author chencong
 * @Description 两个流连在一起
 * @Date 7:42 下午 2021/8/18
 * @Param
 **/
public class Connect {
    public static void main(String[] args) throws Exception {

        //todo
        //1.两个流中存储的数据类型可以不同
        //2.只是机械的合并在一起, 内部仍然是分离的2个流
        //3.只能2个流进行connect, 不能有第3个参与
        StreamExecutionEnvironment streamTableEnvironment = FlinkTableEnv.getStreamTableEnvironment();
        streamTableEnvironment.setParallelism(1);

        DataStreamSource<Integer> intStream = streamTableEnvironment.fromElements(1, 2, 3, 4, 5);
        DataStreamSource<String> stringStream = streamTableEnvironment.fromElements("a", "b", "c");
        // 把两个流连接在一起: 貌合神离

        ConnectedStreams<Integer, String> cs = intStream.connect(stringStream);

        cs.getFirstInput().print("first");
        cs.getSecondInput().print("second");

        streamTableEnvironment.execute();
    }
}
